package cn.tedu.property.management.controller;

import cn.tedu.property.management.pojo.dto.ChargeDetailAddNewDTO;
import cn.tedu.property.management.pojo.dto.ChargeDetailUpdateDTO;
import cn.tedu.property.management.pojo.vo.ChargeDetailStandardVO;
import cn.tedu.property.management.service.IChargeDetailService;
import cn.tedu.property.management.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理费用详情模块的控制器
 */
@RestController
@RequestMapping("/charge/detail")
@Slf4j
@Api(tags = "费用详情模块")
public class ChargeDetailController {

    @Autowired
    private IChargeDetailService chargeDetailService;

    @PostMapping("add-new")
    @ApiOperation("添加费用详情")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(ChargeDetailAddNewDTO chargeDetailAddNewDTO){
        log.debug("开始处理添加费用详情的请求，参数：{}", chargeDetailAddNewDTO);
        chargeDetailService.addNew(chargeDetailAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("删除费用详情")
    @ApiOperationSupport(order = 200)
    private JsonResult deleteByChargeItemId(Long ChargeItemId){
        log.debug("开始处理删除费用详情的请求，参数：{}", ChargeItemId);
        chargeDetailService.deleteByChargeItemId(ChargeItemId);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改费用详情")
    @ApiOperationSupport(order = 300)
    private JsonResult update(Long id , ChargeDetailUpdateDTO chargeDetailUpdateDTO){
        log.debug("开始处理删除费用详情的请求，id为：{} ，参数：{}", id ,chargeDetailUpdateDTO);
        chargeDetailService.update(id , chargeDetailUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/select-item")
    @ApiOperation("根据项目id查询费用详情")
    @ApiOperationSupport(order = 400)
    private JsonResult<ChargeDetailStandardVO> selectByItemID(Long chargeItemId){
        log.debug("开始处理查询费用详情的请求，参数：{}", chargeItemId);
        ChargeDetailStandardVO chargeDetailStandardVO = chargeDetailService
                .selectByStandardByChargeItemId(chargeItemId);
        return JsonResult.ok(chargeDetailStandardVO);
    }

    @GetMapping("/select")
    @ApiOperation("根据业主id查询费用详情")
    @ApiOperationSupport(order = 410)
    private JsonResult<ChargeDetailStandardVO> selectByOwnerId(Long ownerId){
        log.debug("开始处理查询费用详情的请求，参数：{}", ownerId);
        ChargeDetailStandardVO chargeDetailStandardVO = chargeDetailService
                .selectByStandardByOwnerId(ownerId);
        return JsonResult.ok(chargeDetailStandardVO);
    }

}
